package com.envper.controller.cls;

import com.envper.common.domain.dto.ClassMemberDto;
import com.envper.common.service.cls.ClassMemberService;
import com.envper.mysql.domain.Result;
import com.envper.mysql.domain.Status;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/class/member")
public class MemberController {
    private final ClassMemberService classMemberService;

    @GetMapping("/list")
    public Result<List<ClassMemberDto>> getClassMemberList(@RequestParam(name = "id", required = false) String id) {
        List<ClassMemberDto> classMemberList;
        if (StringUtils.hasText(id)) {
            classMemberList = classMemberService.getClassMemberList(id);
        } else {
            classMemberList = classMemberService.getClassMemberList();
        }
        return Result.ok(Status.SUCCESS, classMemberList);
    }

    @PostMapping("/add")
    public Result<String> addClassMember(@RequestBody ClassMemberDto classMemberDto) {
        return Result.ok();
    }
}
